<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/cloudiary.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Cloudiary</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->

<!-- InstanceEndEditable -->
<link href="CSS/css.css" rel="stylesheet" type="text/css" />
</head>
<?php
  include('adminlock.php');
?>
<body>
<div id="container">
<div id="wrapper">

<div id="header">
<!-- InstanceBeginEditable name="header" -->
<div class="welcome">
<?php include('welcomeadmin.php'); ?>
</div>
<!-- InstanceEndEditable -->

<img src="Assets/cloud diary low-01(trans).png" alt="CloudDiary" width="75" height="45" style="padding:5px 10px;" /> <br />
</div>

<div id="main">
	<!-- InstanceBeginEditable name="Main" -->
<div id="admin">
  <?php  
    
    if($_SERVER["REQUEST_METHOD"] == "POST")
    { 
      $_SESSION['view'] = $_POST['viewID'];
      $id = $_SESSION['view'];	
    }
    else
    {
      if(isset($_SESSION['view'])){
        $id = $_SESSION['view'];}
        
      else{echo "Cannot apply session";}
    }
    
    $single_page=3;
	$query="SELECT post_ID, user_email, post_date, post_time, post_edit_date, post_edit_time ,privacy_type, post_topic,SUBSTR(post,1,300) FROM post WHERE user_email='$id'";
    $query_name=mysql_query($query);
    $count=mysql_num_rows($query_name);
    $total_pages=ceil($count/$single_page);
    
    if(isset($_GET['page']) && is_numeric($_GET['page']))
    {
      $obtain_page=$_GET['page'];
      if($obtain_page>0 && $obtain_page<=$total_pages)
      {
        $starting_page=($obtain_page-1)*$single_page;
        $ending_page=$starting_page+$single_page;
      }
      else
      {
        $starting_page=0;
        $ending_page=$starting_page+$single_page;
      }
    }
    else
    {
      $starting_page=0;
      $ending_page=$starting_page+$single_page;
    }   
    
	$q = $query . " LIMIT $starting_page,$single_page";
    $q=mysql_query($q);
    
?>
<div id="page">
<?php
	echo"<p><strong>Page: &nbsp;</strong>";
    for($a=1;$a<=$total_pages;$a++)
    { 
      echo"<a href='AdminPosts.php?page=$a'>$a</a>"." | ";
    }
?>
</div>
<?php
    echo"</p>";
    
    if($count==0)
    {
      echo "No posts to show for this user";
    }
    
    for($a=$starting_page;$a<$ending_page;$a++)
    {
      if($a==$count)
      {
        break;
      }
      
      while($data_fetch=mysql_fetch_array($q))
      {
      ?>
        <table border="0" width="100%">
        <tr>
        <td width="25" rowspan="4">&nbsp;  </td>
        <td colspan="8">&nbsp;  </td> 
        <td width="25" rowspan="4">&nbsp;  </td>
        </tr>
        
    <tr> 
        <td width="150" rowspan="2" align="center">
        <img src="display_photo.php?id=<?php echo $id; ?>" alt="User picture"  width="150" height="170" style="border:1px solid #69F; padding:2px" /> </td>
        <td width="20" rowspan="2" style="border-right:solid 1px #69F"> </td>
        <td  colspan="5">
      
      <?php  
        
        echo "<p style='font-size:16px;font-weight:bold'> &nbsp; Topic: ";
        echo $data_fetch['post_topic'] ."</p>";     
         
        echo"<p> &nbsp; ". $data_fetch['SUBSTR(post,1,300)'] ."</p>";     
       
        $sql="SELECT user_name FROM user WHERE user_email='$id'";
        $q1=mysql_query($sql);
        $data=mysql_fetch_array($q1);
        $user_name=$data['user_name'];
       
       
      ?>
        <p>&nbsp;</p>
        <p>&nbsp;</p></td>
        
        <td width="200" align="right" rowspan="2">
          
          <p>
            <form name="view"  method="POST" action="AdminComments.php" class="view_button">
              <input type="hidden" name="viewID" value="<?php echo $data_fetch["post_ID"]; ?>"/>
              <input type="image" src="Assets/buttonView.png" value="View" />
            </form>
          </p>
          
          <p>
            <form name="delete" action="SQL.php" method="POST" class="delete_button">
              <input type="hidden" name="query" value="<?php echo "DELETE FROM post WHERE post_ID='".$data_fetch['post_ID']."'"; ?>"/>
			  <input type="hidden" name="location" value="<?php echo "AdminPosts.php"; ?>"/>
              <input type="image" src="Assets/buttonDelete.png" value="Delete" />
            </form>
          </p>
         
        </td>
    
    </tr>
    
    <tr> 
    <td height="30px" align="center" style="color:#999; font-size:11px"> &nbsp; Posted On: <?php echo "".$data_fetch['post_date'].""; ?></td>
	<td height="30px" align="center" style="color:#999; font-size:11px"> &nbsp; Posted On: <?php echo "".$data_fetch['post_time'].""; ?></td>
	<td height="30px" align="center" style="color:#999; font-size:11px"> &nbsp; Last Update On: <?php echo "".$data_fetch['post_date'].""; ?></td>
	<td height="30px" align="center" style="color:#999; font-size:11px"> &nbsp; Last Update On: <?php echo "".$data_fetch['post_time'].""; ?></td>
    <td align="center" height="30px" style="color:#999; font-size:11px"> Posted By: <?php echo $user_name; ?>&nbsp; &nbsp;  </td>
    </tr>
    
    <tr> <td colspan="8"  style="border-bottom:solid 1px #69F;">&nbsp;  </td> </tr>
    </table>
  
  <?php  

      }
    }
  
  ?>  
</div>
    <!-- InstanceEndEditable -->
</div>

</div>
</div>

<div id="footer">
<p align="center"> &copy; &nbsp; 2012 CloudDiary </p>
</div>
</body>
<!-- InstanceEnd --></html>
